﻿using Framework;

public class ModifyPropertyEffector : BaseEventEffector
{
    public string StatusName;
    public bool ForSelf;
    public bool IsSetAbsoluteValue;
    public int Value;

    public override void DoEvent(ObjHandle<LogicEntity> owner, params object[] allParams)
    {
        ObjHandle<LogicEntity> target = ForSelf ? FightGame.Instance.GetMyEntity(owner.handle.PlayerID) : FightGame.Instance.GetRivalEntity(owner.handle.PlayerID);
        LogicStatusComponent statusComponent = target.handle.GetLogicComponent<LogicStatusComponent>();
        if (IsSetAbsoluteValue)
        {
            statusComponent[StatusName] = Value;
        }
        else
        {
            statusComponent[StatusName] += Value;
        }
    }

    public override void OnDestroy()
    {
    }

    public override void Serialize(EByte ms)
    {
        ms.WriteString(StatusName);
        ms.WriteInt(ForSelf ? 1 : 0);
        ms.WriteInt(IsSetAbsoluteValue ? 1 : 0);
        ms.WriteInt(Value);
    }

    public override void Deserialize(EByte ms)
    {
        StatusName = ms.ReadString();
        ForSelf = ms.ReadInt() == 1;
        IsSetAbsoluteValue = ms.ReadInt() == 1;
        Value = ms.ReadInt();
    }
}
